local filename = "updateroleinfo.lua"

local timetool = require "timetool"
local skynet = require "skynet"
local cluster = require "skynet.cluster"
local filelog =require "filelog"
local redisdao = require "redisdao"
local json = require "cjson"
json.encode_sparse_array(true,1,1)

local service = nil
local CMD = {
	service = nil
}

-- socket传来的 updateroleinfo  client 类型请求
-- 在agent.cmd 中，也有一个 updateroleinfo 方法，是处理service之间的lua 类型请求
function CMD.process(rid, msgbody)
	if not service then
		service = CMD.service
	end

    local otherinfos = {}
	for k,v in pairs(msgbody) do
        if k == "intro" then    --个人简介过滤铭感词
            local result, words = redisdao.query_data(".gmmqredis", "get", "sensitiveWords")
            if result and words then
                words = json.decode(words) or { }
                v = service:filterSensitiveWords(v,words)
                msgbody[k] = v
            end
        end
		if service.info[k] then
			service.info[k] = msgbody[k]
		end
        if k == "alipay_realname" or k == "bankcard_realname" 
        or k == "weixin_realname" or k == "bankcard_bankname" then
            otherinfos[k] = v
            msgbody[k] = nil
        end
	end

    if next(msgbody) ~= nil then
	    cluster.call("datanode", ".router", "update_rk", rid, "rs_info", 0, msgbody)
    end
    if next(otherinfos) ~= nil then
        cluster.call("datanode", ".router", "update_rk", rid, "rs_otherinfo", 0, otherinfos)
    end

	return {}
end

return CMD